import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@WebServlet("/stu")
public class StudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        List<Student> studentList =new ArrayList<>();
        Student student1=new Student();
        student1.setId(1);
        student1.setNum(10001);
        student1.setName("zhangshan");
        Student student2=new Student();
        student2.setId(2);
        student2.setNum(10002);
        student2.setName("zhangsi");
        Student student3=new Student();
        student3.setId(3);
        student3.setNum(10003);
        student3.setName("zhangwu");
        Student student4=new Student();
        student4.setId(4);
        student4.setNum(10004);
        student4.setName("zhangliu");
        studentList.add(student1);
        studentList.add(student2);
        studentList.add(student3);
        studentList.add(student4);
        req.setAttribute("students", studentList);

        req.getRequestDispatcher("/student.jsp").forward(req, resp);

    }
}
